classdef TestSpatialGradient
    %TestSpatialGradient

    properties (Constant)
        img = uint8([...
            0 0 0 0 0 0 0 0 0 0 ; ...
            0 0 0 0 0 0 0 0 0 0 ; ...
            0 0 0 0 0 0 0 0 0 0 ; ...
            0 0 0 1 1 1 0 0 0 0 ; ...
            0 0 0 1 1 1 0 0 0 0 ; ...
            0 0 0 1 1 1 0 0 0 0 ; ...
            0 0 0 0 0 0 0 0 0 0 ; ...
            0 0 0 0 0 0 0 0 0 0 ; ...
            0 0 0 0 0 0 0 0 0 0 ; ...
            0 0 0 0 0 0 0 0 0 0 ; ...
        ]);
    end

    methods (Static)
        function test_1
            [dx,dy] = cv.spatialGradient(TestSpatialGradient.img);
            validateattributes(dx, {'int16'}, ...
                {'size',size(TestSpatialGradient.img)});
            validateattributes(dy, {'int16'}, ...
                {'size',size(TestSpatialGradient.img)});
        end

        function test_2
            [dx,dy] = cv.spatialGradient(TestSpatialGradient.img, ...
                'KSize',3, 'BorderType','Default');
            validateattributes(dx, {'int16'}, ...
                {'size',size(TestSpatialGradient.img)});
            validateattributes(dy, {'int16'}, ...
                {'size',size(TestSpatialGradient.img)});
        end

        function test_validate
            [dx,dy] = cv.spatialGradient(TestSpatialGradient.img, 'KSize',3);
            dx_ref = cv.Sobel(TestSpatialGradient.img, 'DDepth','int16', ...
                'XOrder',1, 'YOrder',0, 'KSize',3);
            dy_ref = cv.Sobel(TestSpatialGradient.img, 'DDepth','int16', ...
                'XOrder',0, 'YOrder',1, 'KSize',3);
            assert(isequal(dx, dx_ref))
            assert(isequal(dy, dy_ref))
        end

        function test_error_argnum
            try
                cv.spatialGradient();
                throw('UnitTest:Fail');
            catch e
                assert(strcmp(e.identifier,'mexopencv:error'));
            end
        end
    end

end
